package com.test.springCloud.utils;
/**
* @author:LuoXingFa;
* @version:Date:2022年8月2日上午10:47:49
*/

import java.util.Base64;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;

/**
 * base64解密
 *
 */
public class Base64ToImage {

	private static final Logger log = LoggerFactory.getLogger(Base64ToImage.class);
	
	public static MultipartFile base64MultiFile(String imgStr) {
		try {
			String[] baseStr = imgStr.split(",");//分割成数组
			byte[] b = new byte[0];
			b = Base64.getDecoder().decode(baseStr[1]);//base64解密
			for (int i = 0; i < b.length; i++) {
				if (b[i]<0) {
					b[i] +=256;
				}
			}
			return new Base64CodeMultiFileUtil(b, baseStr[0]);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
